package weaver.interfaces.ht.wlbmsq;

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;
import com.weaver.integration.datesource.SAPInterationOutUtil;
import com.weaver.integration.log.LogInfo;
import weaver.general.Util;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-04-11
 * @Description: ${description}
 * @ModifyLog:
 **/

public class ZMM_UPDATE_MATERIAL_CLASS {
    public Map execute(Map<String, String> map) {
        SAPInterationOutUtil outUtil = new SAPInterationOutUtil();
        JCO.Client myConnection = (JCO.Client)outUtil.getConnection("1", new LogInfo());
        myConnection.connect();
        JCO.Repository myRepository = new JCO.Repository("Repository",myConnection); // 只一个名字
        IFunctionTemplate ft = myRepository.getFunctionTemplate("ZMM_UPDATE_MATERIAL_CLASS");//设置BAPI函数
        JCO.Function bapi = ft.getFunction();
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理

        //入参
        input.setValue(map.get("I_MATNR"), "I_MATNR");//参数
        input.setValue(map.get("I_CLASS2"), "I_PLANT");//参数
        input.setValue(map.get("I_CLASS3"), "I_CHNAME");//参数
        //执行函数
        myConnection.execute(bapi);
		
		JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理
        //返回处理结果以及日志
        Map<String, String> mapreturn = new HashMap<>();
        String o_result = Util.null2String(out.getValue("o_result"));//成功失败标识
        mapreturn.put("o_result", o_result);
        System.out.println(mapreturn.toString());
		
        JCO.releaseClient(myConnection);
		return mapreturn;
    }

    public static void main(String[] args) {
        ZMM_UPDATE_MATERIAL_CLASS comm_code = new ZMM_UPDATE_MATERIAL_CLASS();
        Map<String,String> map = new HashMap<>();
        map.put("I_MATNR","1000");
        map.put("I_CLASS2","1000");
        map.put("I_CLASS3","1000");
        comm_code.execute(map);
    }
}
